﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace WpfApplication1
{
	/// <summary>
	/// Interaction logic for Button.xaml
	/// </summary>
	public partial class Button : UserControl
	{
		public Button()
		{
			this.InitializeComponent();
            wait.Interval = TimeSpan.FromMilliseconds(300);
            wait.Tick += new EventHandler(wait_Tick);
		}
		public string Text
		{
			get{
				return this.txt_Text.Text;
			}
			set{
				this.txt_Text.Text=value;
			}
		}
		private void LayoutRoot_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
		{
			VisualStateManager.GoToState(this,"MouseOver",true);
		}

		private void LayoutRoot_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
		{
			VisualStateManager.GoToState(this,"Default",true);
		}

		private void LayoutRoot_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
			VisualStateManager.GoToState(this,"Click",true);
            wait.Start();
		}
        void wait_Tick(object sender, EventArgs e)
        {
            wait.Stop();
            Action temp = () =>
            {
                if (OnClick != null)
                    OnClick(this);
            };
            this.Dispatcher.Invoke(temp);
        }
        public event Action<object> OnClick;
        DispatcherTimer wait = new DispatcherTimer();
	}
}